<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .active {
      color: red;
      font-size: 24px;
      background-color: green;
    }
  </style>
</head>

<body>
  <div class="box">我是box</div>
  <div class="box1">我是box1</div>
  <div class="box2">我是box2</div>

  <script>
    var boxEl = document.querySelector('.box')
    var box1El = document.querySelector('.box1')
    var box2El = document.querySelector('.box2')
    var counter = 1
    // 直接修改style
    boxEl.onclick = function () {
      boxEl.style.color = 'red'
      boxEl.style.fontSize = '24px'
      boxEl.style.backgroundColor = 'green'
    }
    // 动态添加class(推荐)
    box1El.onclick = function () {
      box1El.className = 'active'
    }
    box2El.onclick = function () {
      box2El.className = 'active'
      box2El.style.width = 100 * counter++ + "px"
    }
  </script>
</body>

</html>